// pages/market/comment/index.js
import api from '../../../utils/api'
import message from '../../../utils/message'
Page({

    /**
     * 页面的初始数据
     */
    data: {

        order_list:[],
        comment_list:[],
        tab_index: 0,
        no_comment_data: false,
        comment_page_index:1,
        has_load:true
        
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

        this.getUserShopOrderNoCommentList();

        this.getUserShopOrderCommentList()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    getUserShopOrderNoCommentList: function () {
        //加载待评价的订单
        var me = this;
        message.show_loading();


        api.shop.getUserShopOrderNoCommentList( {} , function (response) {
            message.hide_loading();

            if( response.status==1 ){
                me.setData({
                    order_list: response.data
                })
            }else{
                message.show_error( response.message )
            }   
        })
    },

    getUserShopOrderCommentList:function () {
        var me = this;


        var params ={};
        var page_index = this.data.comment_page_index;
        page_index++;

        params.page_index = page_index;

        message.show_loading();
        api.shop.getUserShopOrderCommentList( params , function (response) {
            message.hide_loading();


            if(response.status==1){

                var list = response.data;


                var no_comment_data = false; 

                var len = list.length;

                if(len<10){
                    no_comment_data = true;
                }
                for(var i=0;i<len ;i++){
                    var images = list[i].images;
                    try{
                        images = JSON.parse( images );
                        list[i].images = images;
                    }catch( err){
                        list[i].images = [];
                    }
                }

                var comment_list = me.data.comment_list;

                comment_list = comment_list.concat( list );
                me.setData({
                    comment_list: comment_list,
                    no_comment_data: no_comment_data,
                    comment_page_index: page_index 
                })
            }else{
                message.show_error( response.message )
            }
        } )
    },
    currentChange:function(e){
        this.setData({
            tab_index: e.detail.current
        })
    },

    selectTab:function (e) {
        var index = e.currentTarget.dataset.index;
        this.setData({
            tab_index: index
        })
        
    }

    
})